#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, mod, R;
ll ans = 0;
ll a[N];
ll mx[N << 2];
void update(int x, ll val, int p, int l, int r) {
  if (l == r) {
    mx[p] = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, val, p << 1, l, mid);
  else
    update(x, val, p << 1 | 1, mid + 1, r);
  mx[p] = max(mx[p << 1], mx[p << 1 | 1]);
}
ll query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return mx[p];
  ll res = 0;
  int mid = (l + r) >> 1;
  if (L <= mid) res = max(res, query(L, R, p << 1, l, mid));
  if (R > mid) res = max(res, query(L, R, p << 1 | 1, mid + 1, r));
  return res;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> mod;
  rep(i, 1, n) {
    char op;
    ll x;
    cin >> op >> x;
    if (op == 'Q') {
      int L = R + 1 - x;
      ans = query(L, R, 1, 1, n);
      cout << ans << endl;
    } else {
      x = (x + ans) % mod;
      update(++R, x, 1, 1, n);
    }
  }
  return 0;
}